﻿
using Furion;
using SqlSugar;
using StackExchange.Redis;

namespace rfid9500_Mqtt
{
    public class ServiceStartup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        
           // ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
            // services.AddSingleton<ConnectionMultiplexer>(redis);

            var configConnection = new ConnectionConfig()
            {
                DbType = SqlSugar.DbType.MySql,
                ConnectionString = App.Configuration["ConnectionStrings:mysql"],
                IsAutoCloseConnection = true,

                InitKeyType = InitKeyType.Attribute//从特性读取主键自增信息
            };

            SqlSugarScope sqlSugar = new SqlSugarScope(configConnection,
                db =>
                {

                    db.Aop.OnError = (ee) =>
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ee.Message);
                        Console.ForegroundColor = ConsoleColor.White;
                    };

                    //单例参数配置，所有上下文生效
                    db.Aop.OnLogExecuting = (sql, pars) =>
                    {
                        //Console.WriteLine(sql);//输出sql
                        // Console.WriteLine(UtilMethods.GetSqlString(DbType.MySql, sql, pars));
                    };
                });
            services.AddSingleton<ISqlSugarClient>(sqlSugar);
            services.AddHostedService<Worker>();
            


        }
    }
}
